package tracksystem;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import managesystem.SM;

import controlsystem.CM;
import controlsystem.Course;

public class TrackSchoolServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest req, HttpServletResponse resp){
			String course = req.getParameter("course");
			System.out.println(req.getParameter("seconds"));
			int duration = Integer.valueOf(req.getParameter("seconds"));
			String place = req.getParameter("place");
			int pages = Integer.valueOf(req.getParameter("pages"));
			String type = req.getParameter("type");
			int rating = Integer.valueOf(req.getParameter("rating"));
			String comment = req.getParameter("comment");
			String description = req.getParameter("description");
			List<Course> courseObj = CM.get().getAvailableCourses();
			Course co = null;
			for(Course c : courseObj){
				if(c.getName().equals(course)){
					co=c;
				}
			}
		
			SchoolActivity sa = new SchoolActivity(duration,place,description,rating,type,comment,co,pages);
			TM.get().saveSchoolAct(sa);
			SM.get().getCurrStud().addActivity(sa);
			SM.get().update();
			HttpSession session = req.getSession();
			session.setAttribute("message", "SchoolActivity tracked succesfull");
			try {
				resp.sendRedirect("/index.jsp");
			} catch (IOException e) {
				e.printStackTrace();
			}
	}
}